﻿using UnityEngine;
using System.Collections;

public class MessageDialog : MonoBehaviour {

    [SerializeField]
    public UIToolkit uitoolkitFonts;
    [SerializeField]
    public UIToolkit uitoolkitBackground;

    private UIText txtTe;
    private UISprite uisBackgroundMessage;
    private UITextInstance txtMoney;
    private string sConversationText = "";
	void Start () 
    {
        CreateControls();
        PositionControls();
        SetTextConversation();
    }

    private void SetTextConversation()
    {
        sConversationText = "Informadora Universidad: \n Hola. \n Bienvenido, quieres estudiar. \n El costo es de $3,000,000";
    }

    private UISprite GetBackGroundMessage()
    {
        if (uisBackgroundMessage == null)
        {
            uisBackgroundMessage =  UI.firstToolkit.addSprite("FondoMenu2b.png", 0, 0, 2);
        }
        return uisBackgroundMessage;
    }

    private void PositionControls()
    {
        uisBackgroundMessage.positionCenter();
    }

    private void CreateControls()
    {
        GetBackGroundMessage();
        txtTe = new UIText(uitoolkitFonts, "prototype", "prototype.png");
        txtMoney = txtTe.addTextInstance(sConversationText, 0, 0);
        txtMoney.textScale = 0.7f;
        txtTe.wrapMode = UITextLineWrapMode.MinimumLength;
        txtTe.lineWrapWidth = GetBackGroundMessage().width;
        //txtMoney.positionCenter();
        txtMoney.parentUIObject = GetBackGroundMessage();
    }

    private void ShowConversation()
    {
        GetBackGroundMessage().hidden = false;
        txtMoney.hidden = false;
        txtMoney.text = sConversationText;
        
        txtTe.updateText(txtMoney);
    }

    private void HideConversation()
    {
        GetBackGroundMessage().hidden = true;
        txtMoney.hidden = true;
    }

    void Update()
    {
        if (ScreenGeneral.StartTalk)
            ShowConversation();
        else
            HideConversation();
    }

}
